from django.utils import simplejson

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from models import *

class TagsCloud(webapp.RequestHandler):
	def get(self):
		tags = Tag.all().order('name').fetch(100)

		# convert into list/dict
		tagList = [tag.json() for tag in tags]

		# convert result into JSON serializable object
		self.response.out.write(simplejson.dumps(tagList))

class TagsAll(webapp.RequestHandler):
	def get(self):
		tags = Tag.all().fetch(20)

		# convert into list/dict
		tagList = [tag.json() for tag in tags]

		# convert result into JSON serializable object
		self.response.out.write(simplejson.dumps(tagList))

application = webapp.WSGIApplication(
		[
			('/tags/cloud', TagsCloud),
			('/tags/all', TagsAll)
		],
		debug=True)

def main():
	run_wsgi_app(application)

if __name__ == "__main__":
	main()

